﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.ProductionStorageCommands;

namespace ProductIntory.Read.Apis.Application.CommandHandler.ProductionStorageCommandHandlers
{
    public class DeletProductionStorageCommandHandler : IRequestHandler<DeletProductionStorageCommand, ApiResult<int>>
    {
        IBaseRepository<ProductionStorage> ProductionStorage;

        public DeletProductionStorageCommandHandler(IBaseRepository<ProductionStorage> ProductionStorage)
        {
            this.ProductionStorage = ProductionStorage;
        }

        public async Task<ApiResult<int>> Handle(DeletProductionStorageCommand request, CancellationToken cancellationToken)
        {
            var list =await ProductionStorage.GetAll().Where(c=>c.Productionstorage_ID==request.Storage_Id).FirstOrDefaultAsync();
            list.IsDel = true;
            return new ApiResult<int> 
            {
                Code=ApiEnum.success,
                Message="删除成功",
                Data=1
            };
        }
    }
}
